using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using CodePlex.Resourceful;

namespace CodePlex.SpaceBlock.UI
{
    public class BindingSourceFilterManager
    {
        private readonly BindingSource _source;

        private readonly List<string> _predicates;

        public BindingSourceFilterManager(BindingSource source)
        {
            _source = source;
            _predicates = new List<string>();
        }
        public void AddExclude(string name, object value)
        {
            _predicates.Add(string.Format("{0} <> '{1}'", name, value));
            this.Update();
        }

        public void AddInclude(string name, object value)
        {
            _predicates.Add(string.Format("{0} = '{1}'", name, value));
            this.Update();
        }


        public void Clear()
        {
            _predicates.Clear();
            this.Update();
        }

        private void Update()
        {
            if (_predicates.Count == 0)
            {
                _source.Filter = null;
            }
            else
            {
                _source.Filter = Utils.Join(" and ", _predicates);
            }
        }



    }

}
